package com.yanqu.road.server.manger.activity.recycle;

import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.activity.ActivityItemRecycleData;
import com.yanqu.road.entity.enums.eActivityType;
import com.yanqu.road.entity.player.UserBagItem;
import com.yanqu.road.server.logic.mail.MailManager;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.manger.activity.goldautumn.GoldAutumnMgr;

import java.util.ArrayList;
import java.util.List;

public class GoldAutumnRecycleStrategy extends AbstractItemRecycleStrategy {

    @Override
    public void markNeedRecycleItem() {
        ActivityInfo activityInfo = GoldAutumnMgr.getActivityInfo();
        if (activityInfo != null && GoldAutumnMgr.getConfig() != null) {

            //标识 道具 回收 type = 1
            addRecycleItemData(activityInfo, activityInfo.getEndTime() * 1000L + 600 * 1000, GoldAutumnMgr.getConfig().getENERGY_ITEM_ID(), GoldAutumnMgr.getConfig().getSCORE_ITEM_ID(), 1);
        }
    }

    private void addRecycleItemData(ActivityInfo activityInfo,long recycleTime, int itemId, int scoreItemId, int recycleType) {
        List<String> paramList = new ArrayList<>();
        paramList.add(String.valueOf(itemId));
        paramList.add(String.valueOf(scoreItemId));
        paramList.add("0");
        paramList.add(activityInfo.getActivityName());
        ActivityItemRecycleMgr.addRecycleItemData(itemId, activityType, recycleType, recycleTime, paramList);
    }

    @Override
    protected void initActivityType() {
        this.activityType = eActivityType.GoldAutumn.getValue();
    }

    @Override
    protected void doRecycle(long userId, ActivityItemRecycleData data) {
        String titleKey = MailManager.ACTIVITY_GOODS_AUTO_CONSUME_TITLE;
        String contentKey = MailManager.ACTIVITY_GOODS_AUTO_CONSUME_CONTENT;
        if(data.getRecycleType() == 1) {
            item2Score(userId, data, titleKey, contentKey);
        }else if(data.getRecycleType() == 3){
            int itemId = data.getItemId();
            UserBagItem bagItem = getUserBagItem(userId, itemId);
            removeItem(bagItem);
        }
    }

    @Override
    public boolean isActivityRunning() {
        ActivityInfo activityInfo = GoldAutumnMgr.getActivityInfo();
        if(activityInfo == null || GoldAutumnMgr.getConfig() == null){
            GoldAutumnMgr.getLogger().error("GoldAutumn Recycle Fail, Because ActivityInfo is null");
            return false;
        }
        return ActivityMgr.activityInTime(activityInfo);
    }
}
